<template>
	<view class="" style="width: 100vw;height: 100vh">
	<!-- <view 
	style="min-height: 100vh">
		<image class="bg" src="/static/login/log_bg.png" mode="scaleToFill"></image> -->
	<view class="content" :style="{'background':kbackgroundColor}" style="min-height: 100vh">
	
		<hx-navbar title="产品列表" :back="true" :fixed="false" :color="knavTitleColor" barPlaceholder="hidden" transparent="auto"></hx-navbar>
		<view class="wrapper">
			<view class="header">
				<view class="balance">
					<image src="/static/shop/balance_icon.png" mode="scaleToFill"></image>
					<text>{{point}}积分</text>
				</view>
				<view class="operate" :style="[selStyle]">
					<view class="btn" @click="toHome">获取积分</view>
					<view class="text" @click="toConvert">兑换记录</view>
				</view>
			</view>
			<view class="list">
				<template v-for="(item, index) in list">
					<view class="item" :key="index" @click="toDetail(item.id)">
						<view class="cover">
							<image :src="item.image" mode="aspectFill"></image>
						</view>  
						<view class="info" :style="[selStyle]">
							<view class="name">{{item.name}}</view>
							<view class="tip">已兑{{item.has_num}}/库存{{item.num}}</view>
							<view class="price">
								<image src="/static/shop/price_icon.png" mode="scaleToFill"></image>
								<text>{{item.exchange_point}}</text>
							</view>
						</view>
					</view>
				</template>
			</view>
		<view  style="text-align: center;" v-if="list.length===0">
		 <image src="@/static/without.png" style="width:550rpx;margin: 10rpx auto " alt="" mode="widthFix"></image> 
		 </view>
		</view>
	</view>
</view>
</template>

<script>
	export default {
		data() {
			return {
				selStyle: {
					'--selectColorSize': this.$store.state.selectColorSize, //字体颜色
					'--buttonBcak': this.$store.state.buttonBcak,
				},
				point: '0.00',
				list: [],
				page: 1,
				limit: 10,
				last: false
			};
		},
		onLoad() {
			this.getShopList();
		},
		onShow() {
			if (this.$db.get('userToken')) {
				this.$api.userInfo({}, res => {
					if (res.status) {
						this.point = res.data.point;
					}
				});
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getShopList();
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 300);
		},
		onReachBottom() {
			if (!this.last) {
				this.page++;
				this.getShopList();
			}
		},
		methods: {
			// 获取商城列表
			getShopList() {
				this.$api.getShopList({
					page: this.page,
					limit: this.limit
				}, res => {
					console.log(res)
					if (res.status) {
						if (res.data.length == 0) return this.last = true;
						if (this.page == 1) {
							this.list = res.data;
						} else {
							this.lsit = [...this.list, ...res.data];
						}
					}
				});
			},
			toHome() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			toConvert() {
				uni.navigateTo({
					url: '/pages/shop/convert'
				});
			},
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/shop/detail'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrapper {
		position: relative;
		z-index: 2;
		.header {
			width: 100%;
			height: 80rpx;
			padding: 0 21rpx 0 51rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.balance {
				display: flex;
				align-items: center;
				image {
					width: 38rpx;
					height: 36.5rpx;
					display: block;
					margin-right: 13rpx;
				}
				text {
					font-size: 24rpx;
					color: #333;
					font-weight: bold;
				}
			}
			.operate {
				display: flex;
				align-items: center;
				.btn {
					width: 120rpx;
					height: 40rpx;
					background-color:var(--selectColorSize);// #FE005A;
					border-radius: 100rpx;
					text-align: center;
					line-height: 40rpx;
					font-size: 22rpx;
					color: #fff;
				}
				.text {
					font-size: 24rpx;
					color: #333;
					margin-left: 18rpx;
				}
			}
		}
		.list {
			width: 100%;
			padding: 10rpx 40rpx;
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			justify-content: space-between;
			.item {
				width: 325rpx;
				height: 468rpx;
				background-color: #fff;
				border-radius: 20rpx;
				border: 1rpx solid #FCC9CB;
				padding: 10rpx;
				margin-top: 16rpx;
				.cover {
					width: 305rpx;
					height: 305rpx;
					image {
						width: 100%;
						height: 100%;
						display: block;
						border-radius: 20rpx;
					}
				}
				.info {
					padding: 14rpx 8rpx 0;
					.name {
						font-size: 28rpx;
						color: #000;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					.tip {
						font-size: 20rpx;
						color:var(--selectColorSize);// #FE005A;
						margin: 3rpx 0 13rpx;
					}
					.price {
						display: flex;
						align-items: center;
						justify-content: flex-end;
						image {
							width: 31rpx;
							height: 33rpx;
							display: block;
							margin-right: 5rpx;
						}
						text {
							font-size: 32rpx;
							color: #000;
							font-weight: bold;
						}
					}
				}
			}
			& > view:nth-child(-n+2) {
				margin-top: 0;
			}
		}
	}
</style>